sarahClient.js ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 17
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
A sarahClient.js ➔ ... ➔ ??? 0 3 1
1
"use strict";
2
3
const config = require('config').sarah.client;
4
const NestedError = require('nested-error-stacks');
5
const request = require('request-promise-native');
6
7
const defaultOptionList = {
8
    uri: `${config.scheme}://${config.host}:${config.port}`,
9
    headers: {'User-Agent': 'Alfred-server'},
10
    qs: {}, // <-- to override before call
11
    json: true,
12
    simple: true,
13
    resolveWithFullResponse: true
14
};
15
16
/**
17
 * @param {Object} attributeList
18
 * @param {string} httpMethod
19
 *
20
 * @returns {Promise<null|Error>}
21
 */
22
module.exports = (attributeList, httpMethod = 'GET') => {
23
    // Append queryString to default options
24
    const optionList = Object.assign(
25
        defaultOptionList,
26
        {
27
            method: httpMethod,
28
            qs: attributeList
29
        });
30
31
    return request(optionList)
32
        .then(data => {
33
            console.log(`data ${JSON.stringify(data)}`);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
34
        })
35
        .catch(error => {
36
            return Promise.reject(new NestedError('sarahClient error', error));
37
        });
38
};
39